package com.operation.controller;

import com.operation.beans.Result;
import com.operation.entity.AppVersion;
import com.operation.service.AppVersionService;
import com.operation.utils.FileUploadUtil;
import com.operation.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
public class AppVersionServiceController {
    @Autowired
    AppVersionService appVersionService;

    @RequestMapping(value = "/appVersion/{version}",method = RequestMethod.POST)
    public Result uploadAddress(@PathVariable String version, MultipartFile multipartFile, HttpServletRequest httpServletRequest) throws IOException {
        AppVersion appVersion = new AppVersion();
        appVersion.setVersion(version);
        appVersion.setDownloadaddress(FileUploadUtil.singleFileUpload(multipartFile,httpServletRequest));
        return ResultUtil.success(appVersionService.updateDownloadAddress(appVersion),0);
    }
}
